package use_case.processRental;

import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.io.BufferedWriter;
import java.io.IOException;

public class SystemHealthLog {
	private static SystemHealthLog systemHealthLogInstance = null;
	
	private ArrayList<String> systemHealthLogLines;

	protected SystemHealthLog( )
	{
		systemHealthLogLines = new ArrayList<String>();
	}
	
	public static ArrayList<String> getSystemHealthLogLines() {
		if( systemHealthLogInstance == null )
		{
			systemHealthLogInstance = new SystemHealthLog();
		}
		
		return systemHealthLogInstance.systemHealthLogLines;
	}

	public static void logSystemEvent( String eventMessage )
	{
		if( systemHealthLogInstance == null )
		{
			systemHealthLogInstance = new SystemHealthLog();
		}

		systemHealthLogInstance.systemHealthLogLines.add( String.format("%s\t%s\n", 
				DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format( new Date() ), eventMessage ) );
	}
	
	public static void printEvents( BufferedWriter bufferedWriter ) throws IOException
	{
		if( systemHealthLogInstance == null ) return;
		
		for( String s : systemHealthLogInstance.systemHealthLogLines)
		{
			bufferedWriter.write( s );
		}
	}
}
